#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(void)
{
        CascadeClassifier classifier("/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml");
        VideoCapture cap;
	cap.open(0);
	if (!(cap.isOpened()))
	{
		cout << "open error "<<endl;
	}
	Mat image;
	Mat gray;

	while(true)
	{
	cap.read(image);
	cvtColor(image,gray,CV_BGR2GRAY);
	equalizeHist(gray,gray);
	vector<Rect>faces;
	classifier.detectMultiScale(gray,faces);
	if(faces.size())
	{
		rectangle(image,faces[0],CV_RGB(255,0,0));
		
	}
	imshow("Video",image);
	if(waitKey(20)!=255){
		break;

        }
        }
	return 0;

}

